home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-09 | 24.8 KB | 911 lines | [TEXT/CWIE] |
- /*
- File: Window.cp
-
- Contains: Implementation of TWindow, a base class which provides a
- framework for building way-cool windows which even John
- Sullivan would be happy with. Floating windows and “smart
- zooming” algorithms are based on code samples provided by
- Dean Yu. Tim Craycroft, the guy making the window manager
- do all this work for you has also been a great help.
-
- Written by: Dave Falkenburg
-
- Copyright: © 1993-1995 by Dave Falkenburg, all rights reserved.
-
- Change History (most recent first):
-
- <14> 1/24/95 DRF DoMenuSelection now returns a Boolean. Added some default
- behavior for handling the close menu item-- this will change
- when we make some things recordable.
- <13> 1/20/95 DRF Fix the “calling DisposeWindow on DialogPtr” problem reported by
- Gary Powell @ Adobe by adding a cheezy flag that TWindow
- initializes, but TDialogWindow slams. In TWindow::Close, we
- check this flag and call DisposeDialog instead of DisposeWindow,
- surely preventing memory leaks for complex dialogs.
- <12> 1/3/95 DRF Add Nitin’s changes for Drag handling: a ClickAndDrag method.
- <11> 1/3/95 DRF DoMenuCommand now returns a Boolean. Also got rid of
- conditionals for ClipAbove: by the time this gets to print
- everyone should be using Universal Headers 2.0.
- <10> 12/6/94 DRF Rolled in David Den Boer’s fixes. Also add the conditionals for
- newest universal headers again.
- <9> 11/23/94 DRF Bite the bullet just require the latest universal headers
- <8> 11/17/94 DRF Add casts for CFront & PPCC. Also dealt with the change to
- ClipAbove in the latest universal headers.
- <7> 11/12/94 DRF Added AdjustMenusBeforeMenuSelection.
- <6> 11/8/94 DRF Add some better menu handling methods.
- <5> 9/27/94 DRF AppLib.h is now Sprocket.h
- <4> 9/9/94 DRF Reorganized headers and removed redundant #includes.
- <3> 9/4/94 DRF Added DrawJustTheGrowIcon.
- <2> 8/27/94 DRF In TWindow::Close, call window’s (de)Activate method before
- closing so that menus can be properly updated.
-
- To Do: Make sure invisible windows can be created & managed
- Handle modal windows as another class of windows
- Fix activate bugs when showing and hiding windows
- Window positioning methods (getters and setters)
- Display Manager support
- Changes to support AEObject model
- */
-
- #include "Window.h"
- #include "WindowManager.h"
-
- #include "Exceptions.h"
- #include "ForegroundApplication.h"
- #include "Sprocket.h"
- #include "StringUtil.h"
-
- #include <Script.h> // for GetMBarHeight()
- #include <LowMem.h> // for LMGetWindowList()
- #include <AEObjects.h>
- #include <AEPackObject.h>
-
- extern WindowManager gWindowManager;
-
- DragTrackingHandler TWindow::fgDragTrackingHandler = nil;
- DragReceiveHandler TWindow::fgDragReceiveHandler = nil;
- //RgnHandle TWindow::fgScratchRgn = nil;
- //short TWindow::fgNumWindows = 0;
-
-
- static void HiliteShowHideFloatingWindows(Boolean hiliting,Boolean hiding);
- static void FindScreenRectWithLargestPartOfWindow(WindowRef aWindow,Rect *theBestScreenRect, GDHandle * theBestDevice);
- static pascal void CalculateWindowAreaOnDevice(short depth,short deviceFlags,GDHandle targetDevice,long userData);
-
- //--------------------------------------------------------------------------------
- inline Point& topLeft(Rect& r)
- {
- return *(Point*) (&r.top);
- }
-
-
- //--------------------------------------------------------------------------------
- inline Point& botRight(Rect& r)
- {
- return *(Point*) (&r.bottom);
- }
-
-
- //--------------------------------------------------------------------------------
- inline void LocalToGlobal(Rect* r)
- {
- ::LocalToGlobal(&topLeft(*r));
- ::LocalToGlobal(&botRight(*r));
- }
-
-
- //--------------------------------------------------------------------------------
- inline void GlobalToLocal(Rect* r)
- {
- ::GlobalToLocal(&topLeft(*r));
- ::GlobalToLocal(&botRight(*r));
- }
-
- int WithModalDialogHilite::fgNestLevel = 0;
-
- WithModalDialogHilite::WithModalDialogHilite()
- {
- if (fgNestLevel++ <= 0)
- TWindow::BeginModalDialog();
- }
-
- WithModalDialogHilite::~WithModalDialogHilite()
- {
- if (--fgNestLevel <= 0)
- TWindow::EndModalDialog();
- }
-
- WindowRef TWindow::GetNewWindow(
- short windowID,
- WindowRef behind,
- WindowLayer layer)
- {
- return gWindowManager.GetNewWindow(windowID, behind, layer);
- }
-
- WindowRef TWindow::NewWindow(
- const Rect &boundsRect,
- ConstStr255Param title,
- Boolean visible,
- short theProc,
- WindowRef behind,
- Boolean goAwayFlag,
- long refCon,
- WindowLayer layer)
- {
- return gWindowManager.NewWindow(boundsRect, title, visible, theProc, behind, goAwayFlag, refCon, layer);
- }
-
- void TWindow::SuspendApplication(void)
- {
- gWindowManager.SuspendApplication();
- }
-
- void TWindow::ResumeApplication(void)
- {
- gWindowManager.ResumeApplication();
- }
-
- void TWindow::BeginModalDialog(void)
- {
- gWindowManager.BeginModalDialog();
- }
-
- void TWindow::EndModalDialog(void)
- {
- gWindowManager.EndModalDialog();
- }
-
- //--------------------------------------------------------------------------------
- TWindow::TWindow(WindowRef aWindowRef)
- : fWindow(aWindowRef)
- {
- FailNil(aWindowRef);
-
- fNextEventDispatcher = gApplication;
-
- SetWRefCon(aWindowRef,(long) this);
-
- if (fgDragTrackingHandler == nil)
- fgDragTrackingHandler = NewDragTrackingHandlerProc(TWindow::CallWindowDragTrackingHandler);
- if (fgDragReceiveHandler == nil)
- fgDragReceiveHandler = NewDragReceiveHandlerProc(TWindow::CallWindowDragReceiveHandler);
-
- InstallTrackingHandler(fgDragTrackingHandler, aWindowRef, this);
- InstallReceiveHandler(fgDragReceiveHandler, aWindowRef, this);
- }
-
-
- //--------------------------------------------------------------------------------
- void TWindow::IWindow()
- {
- }
-
- //--------------------------------------------------------------------------------
- void TWindow::Dispose()
- {
- if (fWindow)
- {
- OSErr err1 = RemoveTrackingHandler(fgDragTrackingHandler, fWindow);
- OSErr err2 = RemoveReceiveHandler(fgDragReceiveHandler, fWindow);
-
- gWindowManager.DisposeWindow(fWindow);
-
- fWindow = nil;
- }
- }
-
- //--------------------------------------------------------------------------------
- TWindow::~TWindow()
- {
- if (fWindow)
- {
- this->Dispose();
- }
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::EventFilter(EventRecord * /* theEvent */)
- {
- return false;
- }
-
-
- //--------------------------------------------------------------------------------
- void TWindow::Select(void)
- {
- gWindowManager.SelectWindow(fWindow);
- }
-
-
- //--------------------------------------------------------------------------------
- void TWindow::ShowHide(Boolean showFlag)
- {
- // Here we need the “::” in front of ShowHide to indicate we are calling
- // the global function, and not the method ShowHide. Unintended recursion
- // can do bad things to the unsuspecting programmer.
-
- // Some C++ programmers would always prepend the “::” on function calls.
-
- ::ShowHide(fWindow,showFlag);
- }
-
-
- //--------------------------------------------------------------------------------
- // by default do nothing
- void TWindow::AdjustCursor(Point /*where*/)
- {
- }
-
-
- //--------------------------------------------------------------------------------
- // when we become active, we want to get events
- void TWindow::Activate()
- {
- SetCurrentEventDispatcher(*this);
- }
-
-
- //--------------------------------------------------------------------------------
- // when we become inactive, we no longer want to get events
- void TWindow::Deactivate()
- {
- RemoveEventDispatcher(*this);
- }
-
-
- //--------------------------------------------------------------------------------
- void TWindow::Draw(void)
- {
- }
-
-
- //--------------------------------------------------------------------------------
- void TWindow::DrawGrowIcon(void)
- {
- gWindowManager.DrawWindowGrowIcon(fWindow);
- }
-
- //--------------------------------------------------------------------------------
- // by default do nothing
- void TWindow::Click(EventRecord * /* anEvent */)
- {
- }
-
-
- //--------------------------------------------------------------------------------
- // by default do nothing
- void TWindow::KeyDown(EventRecord * /*anEvent*/)
- {
- }
-
-
- //--------------------------------------------------------------------------------
- Rect TWindow::GetGrowSizeRect(void)
- {
- Rect limits;
-
- limits.top = limits.left = kMinimumWindowSize;
- limits.bottom = limits.right = 32000;
-
- return limits;
- }
-
-
- //--------------------------------------------------------------------------------
- // by default do nothing
- void TWindow::AdjustForNewWindowSize(Rect * /* oldRect */, Rect * /* newSize */)
- {
- }
-
-
- //--------------------------------------------------------------------------------
- Rect TWindow::GetBounds(void) const
- {
- GrafPtr oldPort;
- Rect bounds = GetWindowBounds(fWindow);
-
- GetPort(&oldPort);
- SetPortWindowPort(fWindow);
- LocalToGlobal(&bounds);
- SetPort(oldPort);
-
- return bounds;
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::HasCloseBox(void) const
- {
- return GetWindowGoAwayFlag(fWindow);
- }
-
-
- //--------------------------------------------------------------------------------
- // Why isn't this defined in Windows.h ??
- Boolean GetWindowTitleBar(WindowRef fWindow);
- Boolean GetWindowTitleBar(WindowRef fWindow)
- {
- short winKind = GetWVariant(fWindow);
-
- // really ugly ... got a better idea ?? (could look at contRgn vs. strucRgn)
- return ! ((winKind == dBoxProc) || (winKind == plainDBox) || (winKind == altDBoxProc));
- }
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::HasTitleBar(void) const
- {
- return GetWindowTitleBar(fWindow);
- }
-
-
- //--------------------------------------------------------------------------------
- long TWindow::GetIndex(void) const
- {
- return gWindowManager.GetWindowIndex(fWindow, kNormalWindowLayer);
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::IsFloating(void) const
- {
- return gWindowManager.IsWindowFloating(fWindow);
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::IsModal(void) const
- {
- return gWindowManager.IsWindowModal(fWindow);
- }
-
-
- //--------------------------------------------------------------------------------
- // Why isn't this defined in Windows.h ??
- Boolean GetWindowSizeFlag(WindowRef fWindow);
- Boolean GetWindowSizeFlag(WindowRef fWindow)
- {
- short winKind = GetWVariant(fWindow);
-
- // really ugly ... got a better idea ??
- return ((winKind == documentProc) || (winKind == zoomDocProc));
- }
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::IsResizable(void) const
- {
- return GetWindowSizeFlag(fWindow);
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::IsZoomable(void) const
- {
- return GetWindowZoomFlag(fWindow);
- }
-
-
- //--------------------------------------------------------------------------------
- // it would be nice to have a cleaner way to do this
- Boolean TWindow::IsZoomed(void) const
- {
- GrafPtr oldPort;
- Rect zoomedRect;
- Rect bounds = GetWindowBounds(fWindow);
-
- GetPort(&oldPort);
- SetPortWindowPort(fWindow);
- LocalToGlobal(&bounds);
- SetPort(oldPort);
-
- GetWindowStandardState (fWindow, &zoomedRect);
- return EqualRect(&bounds, &zoomedRect);
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::SetZoomed(Boolean zoomed)
- {
- // is this window zoomable ??
- if (!this->TWindow::IsZoomable())
- {
- Fail(errAEEventNotHandled);
- return false;
- }
-
- // if it is, zoom Out or zoom In as the event requested
- if (zoomed)
- gWindowManager.ZoomWindow(fWindow, inZoomOut, this->GetPerfectWindowSize());
- else
- gWindowManager.ZoomWindow(fWindow, inZoomIn, this->GetPerfectWindowSize());
- return true;
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::IsVisible(void) const
- {
- return gWindowManager.IsWindowVisible(fWindow);
- }
-
-
- //--------------------------------------------------------------------------------
- Rect TWindow::SetBounds(Rect r)
- {
- Rect oldBounds = GetWindowBounds(fWindow);
-
- gWindowManager.SetWindowBounds(fWindow, r);
-
- return oldBounds;
- }
-
-
- //--------------------------------------------------------------------------------
- long TWindow::SetIndex(long index)
- {
- // TO DO: move the window to an arbitrary position
- // note that we need to handle negative indices
- // and make sure window stays in the right layer
-
- // Open Issue: Do floating/modal windows count in
- // index?
- return index;
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::SetVisible(Boolean show)
- {
- Boolean result = gWindowManager.IsWindowVisible(fWindow);
-
- if (result != show)
- {
- if (show)
- gWindowManager.ShowWindow(fWindow);
- else
- gWindowManager.HideWindow(fWindow);
- }
-
- return result;
- }
-
-
- //--------------------------------------------------------------------------------
- // by default windows can be closed, override if your window has a different policy
- Boolean TWindow::CanClose(void)
- {
- return true;
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::Close(DescType /*saveOptions*/)
- {
- this->Deactivate();
- this->Dispose();
- return true;
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::DeleteAfterClose(void)
- {
- return true;
- }
-
-
- //--------------------------------------------------------------------------------
- // by default do nothing
- void TWindow::AdjustMenus(void)
- {
- }
-
-
- //--------------------------------------------------------------------------------
- // By default, we just convert to local coordinates and call the window’s Click method.
- void TWindow::ClickAndDrag(EventRecord * anEvent)
- {
- GlobalToLocal(&anEvent->where);
- this->Click(anEvent);
- }
-
-
- //--------------------------------------------------------------------------------
- OSErr TWindow::HandleDrag(DragTrackingMessage dragMessage,DragReference theDrag)
- {
- OSErr result = dragNotAcceptedErr;
-
- switch (dragMessage)
- {
- case dragTrackingEnterWindow:
- result = this->DragEnterWindow(theDrag);
- break;
-
- case dragTrackingInWindow:
- result = this->DragInWindow(theDrag);
- break;
-
- case dragTrackingLeaveWindow:
- result = this->DragLeaveWindow(theDrag);
- break;
-
- default:
- break;
- }
-
- return result;
- }
-
-
- //--------------------------------------------------------------------------------
- OSErr TWindow::DragEnterWindow(DragReference /* theDrag */)
- {
- return dragNotAcceptedErr;
- }
-
-
- //--------------------------------------------------------------------------------
- OSErr TWindow::DragInWindow(DragReference /* theDrag */)
- {
- return dragNotAcceptedErr;
- }
-
-
- //--------------------------------------------------------------------------------
- OSErr TWindow::DragLeaveWindow(DragReference /* theDrag */)
- {
- return dragNotAcceptedErr;
- }
-
-
- //--------------------------------------------------------------------------------
- OSErr TWindow::HandleDrop(DragReference /* theDrag */)
- {
- return dragNotAcceptedErr;
- }
-
-
- Boolean TWindow::IsPointInContentRgn( Point pt )
- {
- return gWindowManager.PointInContentRgn(fWindow, pt);
- }
-
- Rect TWindow::GetContentsBounds(void)
- {
- return gWindowManager.GetWindowContentBounds(fWindow);
- }
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::IsMouseInContentRgn( DragReference dragRef )
- {
- Point globalMouse;
- OSErr err;
-
- err = GetDragMouse( dragRef, &globalMouse, 0L );
-
- if ( err == noErr )
- return( gWindowManager.PointInContentRgn(fWindow, globalMouse));
- else
- return( false );
- }
-
-
- //--------------------------------------------------------------------------------
- // TWindowEventDispatcher overrides
- //--------------------------------------------------------------------------------
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::DispatchContentClick(EventRecord& event, WindowRef window)
- {
- if (fWindow == window)
- {
- GrafPtr oldPort;
- GetPort(&oldPort);
- SetPort((GrafPtr) window);
- GlobalToLocal(&event.where);
- this->Click(&event);
- SetPort((GrafPtr) window);
- return true;
- }
- else
- {
- // the click is in a window that is not activated
- TWindow* win = TWindow::GetWindowObject(window);
-
- if (win)
- win->Select();
- else
- SelectWindow(window); /// TO DO: Fix this for floating windows
-
- return false;
- }
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::DispatchUpdate(EventRecord& event)
- {
- WindowRef w = (WindowRef) event.message;
- GrafPtr p = (GrafPtr) GetWindowPort(w);
- GrafPtr oldPort;
-
- #if qDebug
- // DebugStr("\pDropped update event");
- #endif
-
- GetPort(&oldPort);
- SetPortWindowPort(w);
- BeginUpdate(w);
-
- TWindow* win = TWindow::GetWindowObject(w);
-
- if (win)
- win->Draw();
- else
- EraseRect(&p->portRect);
-
- EndUpdate(w);
- SetPort(oldPort);
-
- return true;
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::DispatchActivateOrResume(EventRecord& /*event*/)
- {
- this->Activate();
-
- return true;
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::DispatchDeactivateOrSuspend(EventRecord& /*event*/)
- {
- this->Deactivate();
-
- return true;
- }
-
-
- //--------------------------------------------------------------------------------
- /// Caution Experimental Function
- //--------------------------------------------------------------------------------
- void RecordWindowBounds (long winIndex, Rect bounds);
- void RecordWindowBounds (long winIndex, Rect bounds)
- {
- CAppleEvent event, reply;
- CAETempDesc windowObject, theData, theProperty, positionDesc, objectToSet, nullDesc;
-
- // " set pBounds of window winIndex of app to bounds"
-
- // descripter for data value
- theData.MakeRect(bounds);
-
- // descriptor for pIsZoomed
- theProperty.MakeDescType(pBounds);
-
- // descriptor for the window object
- FailOSErr(::CreateOffsetDescriptor(winIndex, (AEDesc *) &positionDesc));
-
- nullDesc.MakeNull();
- FailOSErr(::CreateObjSpecifier(cWindow, (AEDesc *) &nullDesc, formAbsolutePosition,
- (AEDesc *) &positionDesc, false, (AEDesc *) &windowObject));
-
- FailOSErr(::CreateObjSpecifier(cProperty, (AEDesc *) &windowObject, formPropertyID,
- (AEDesc *) &theProperty, false, (AEDesc *) &objectToSet));
-
- // let it rip
- // generate a SetData event
- FailOSErr(::AECreateAppleEvent(kAECoreSuite, kAESetData, &TApplication::fgCurrentProcessDesc,
- kAutoGenerateReturnID, kAnyTransactionID, (AEDesc *) &event));
- // Attach the property object specifier.
- FailOSErr(::AEPutParamDesc((AEDesc *) &event, keyDirectObject, (AEDesc *) &objectToSet));
- // Add the property data.
- FailOSErr(::AEPutParamDesc((AEDesc *) &event, keyAEData, (AEDesc *) &theData));
- // Send it for rcording purposes only
- FailOSErr(::AESend((AEDesc *) &event, (AEDesc *) &reply, kAENoReply+kAECanInteract+kAEDontExecute,
- kAENormalPriority, kAEDefaultTimeout, nil, nil));
-
- // Deallocate stuff ??
- }
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::TrackDrag(EventRecord& event, WindowRef window)
- {
- TWindowEventDispatcher::TrackDrag(event, window);
- // record the new window size in an Apple Event - SHOULD RECORD POSITION INSTEAD
- RecordWindowBounds(this->GetIndex(), this->GetBounds());
- return true;
- }
-
-
- //--------------------------------------------------------------------------------
- // mouse down in the grow box, deal with the event here
- Point TWindow::TrackGrow(EventRecord& event, WindowRef window)
- {
- Point newSize = TWindowEventDispatcher::TrackGrow(event, window);
-
- ::SizeWindow(fWindow, newSize.h, newSize.v, true);
- // record the new window size in an Apple Event
- RecordWindowBounds(this->GetIndex(), this->GetBounds());
- return newSize;
- }
-
-
- //--------------------------------------------------------------------------------
- // mouse down in the close box, deal with the event here
- Boolean TWindow::TrackGoAway(EventRecord& event, WindowRef window)
- {
- if (TWindowEventDispatcher::TrackGoAway(event, window))
- Close();
- return true;
- }
-
- //--------------------------------------------------------------------------------
- /// Caution Experimental Function
- //--------------------------------------------------------------------------------
- void PostSetDataToTWin_Zoomed (Boolean flag);
- void PostSetDataToTWin_Zoomed (Boolean flag)
- {
- CAppleEvent event, reply;
- CAETempDesc windowObject, theData, theProperty, positionDesc, objectToSet, nullDesc;
-
- // " set pIsZoomed of window 1 of app to flag"
-
- // descripter for data value
- theData.MakeBoolean(flag);
-
- // descriptor for pIsZoomed
- theProperty.MakeDescType(pIsZoomed);
-
- // descriptor for the window object
- long index = 1; // for now it is always the front window
-
- FailOSErr(::CreateOffsetDescriptor(index, (AEDesc *) &positionDesc));
-
- nullDesc.MakeNull();
- FailOSErr(::CreateObjSpecifier(cWindow, (AEDesc *) &nullDesc, formAbsolutePosition,
- (AEDesc *) &positionDesc, false, (AEDesc *) &windowObject));
-
- FailOSErr(::CreateObjSpecifier(cProperty, (AEDesc *) &windowObject, formPropertyID,
- (AEDesc *) &theProperty, false, (AEDesc *) &objectToSet));
-
- // let it rip
- // generate a SetData event
- FailOSErr(::AECreateAppleEvent(kAECoreSuite, kAESetData, &TApplication::fgCurrentProcessDesc,
- kAutoGenerateReturnID, kAnyTransactionID, (AEDesc *) &event));
- // Attach the property object specifier.
- FailOSErr(::AEPutParamDesc((AEDesc *) &event, keyDirectObject, (AEDesc *) &objectToSet));
- // Add the property data.
- FailOSErr(::AEPutParamDesc((AEDesc *) &event, keyAEData, (AEDesc *) &theData));
- // Send it
- FailOSErr(::AESend((AEDesc *) &event, (AEDesc *) &reply, kAENoReply, kAENormalPriority,
- kAEDefaultTimeout, nil, nil));
-
- // Deallocate stuff ??
- }
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::TrackZoomIn(EventRecord& event, WindowRef window)
- {
- if (TWindowEventDispatcher::TrackZoomIn(event, window))
- PostSetDataToTWin_Zoomed(false);
- // TWindow::ZoomWindow(fWindow, inZoomIn, this->GetPerfectWindowSize());
- return true;
- }
-
-
- //--------------------------------------------------------------------------------
- Boolean TWindow::TrackZoomOut(EventRecord& event, WindowRef window)
- {
- if (TWindowEventDispatcher::TrackZoomOut(event, window))
- PostSetDataToTWin_Zoomed(true);
- // TWindow::ZoomWindow(fWindow, inZoomOut, this->GetPerfectWindowSize());
- return true;
- }
-
- //--------------------------------------------------------------------------------
- void TWindow::AEGetNameDesc(CAEDesc& value, const CAETypeList& /*requestedTypes*/) const
- {
- Str255 title;
-
- ::GetWTitle(fWindow, title);
- value.MakeString(title);
- }
-
-
- //--------------------------------------------------------------------------------
- void TWindow::AESetNameDesc(const CAEDesc& name)
- {
- Str255 title;
-
- name.GetString(title);
-
- ::SetWTitle(fWindow, title);
- }
-
- //--------------------------------------------------------------------------------
- // this window has gotten an AEClose event, execute it here
- void TWindow::HandleAEClose(AEServerEvent& /*event*/)
- {
- /// we should look at the event to see if there are optional arguments, but for now ...
-
- // just do it
- if (this->CanClose())
- this->Close();
- else
- Fail(errAEEventNotHandled);
- }
-
- //--------------------------------------------------------------------------------
- // Utility Functions used for floating windows
- //--------------------------------------------------------------------------------
-
- //--------------------------------------------------------------------------------
-
-
- TWindow* TWindow::GetWindowObject(WindowRef aWindow)
- {
- TWindow* result = nil;
- short wKind;
-
- if (aWindow != nil)
- {
- wKind = GetWindowKind ( aWindow );
-
- if (wKind >= userKind)
- {
- // All windowKinds >= userKind are based upon TWindow
- result = (TWindow *) GetWRefCon(aWindow);
- }
- }
- return result;
- }
-
-
- //--------------------------------------------------------------------------------
- TWindow* TWindow::GetNthWindow(long index, WindowLayer layer)
- {
- return TWindow::GetWindowObject(gWindowManager.GetNthWindow(index, layer));
- }
-
-
- //--------------------------------------------------------------------------------
- // find any type of window with the input name
- TWindow* TWindow::GetNamedWindow(ConstStr255Param name, WindowLayer layer)
- {
- return TWindow::GetWindowObject(gWindowManager.GetNamedWindow(name, layer));
- }
-
-
- //--------------------------------------------------------------------------------
- // Drag Manager callback routines which dispatch to a window’s method
- //--------------------------------------------------------------------------------
-
- pascal OSErr TWindow::CallWindowDragTrackingHandler(DragTrackingMessage dragMessage,
- WindowRef theWindow, void * /* refCon */,DragReference theDrag)
- {
- TWindow *wobj = TWindow::GetWindowObject(theWindow);
-
- if (wobj)
- return(wobj->HandleDrag(dragMessage,theDrag));
- else
- return dragNotAcceptedErr;
- }
-
- pascal OSErr TWindow::CallWindowDragReceiveHandler(WindowRef theWindow, void * /* refCon */,
- DragReference theDrag)
- {
- TWindow *wobj = TWindow::GetWindowObject(theWindow);
-
- if (wobj)
- return(wobj->HandleDrop(theDrag));
- else
- return dragNotAcceptedErr;
- }
-
-
-